package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.ChannelDto;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/channel")
@Api(value = "频道管理",tags = "频道管理")
public class WmChannelController {

    @Autowired
    private WmChannelService wmChannelService;

    @ApiOperation("查询频道列表")
    @GetMapping("/channels")
    public ResponseResult findAll(){
        return wmChannelService.findAll();
    }

    /**
     * 条件分页查询频道列表
     * @return
     */
    @PostMapping("/list")
    public ResponseResult getChannelPage(@RequestBody ChannelDto dto){
        return wmChannelService.getChannelPage(dto);
    }

    /**
     * 新增频道
     * @param wmChannel
     * @return
     */
    @PostMapping("/save")
    public ResponseResult insert(@RequestBody WmChannel wmChannel){
        return wmChannelService.insert(wmChannel);
    }

    /**
     * 修改频道
     * @param wmChannel
     * @return
     */
    @PostMapping("/update")
    public ResponseResult edit(@RequestBody WmChannel wmChannel){
        return wmChannelService.edit(wmChannel);
    }

    /**
     * 删除频道
     * @param id
     * @return
     */
    @GetMapping("/del/{id}")
    public ResponseResult del(@PathVariable("id") Integer id){
        return wmChannelService.del(id);
    }
}
